package com.xpgk.app.customer;

import com.jfinal.core.Controller;
import com.xpgk.dto.AjaxRender;
import com.xpgk.mvc.base.BaseValidator;
import com.xpgk.mvc.bentryRegister.Customer;
import com.xpgk.mvc.bentryRegister.CustomerDetail;

import jodd.util.StringUtil;

public class AppCustomerInfoValidator extends  BaseValidator{

	@Override
	protected void validate(Controller paramController) {
		
		String actionKey = getActionKey();
		if(actionKey.equals("/customerInfo/saveCustomer"))
		{	
			Customer customer = controller.getModel(Customer.class);
			String   mAge= getPureText("mAge");
			String   sex=customer.getStr(Customer.column_sex);
			if(StringUtil.isBlank(mAge)){
				addError("msg", "请输入出生年月");
				return;
			}
			if(StringUtil.isBlank(sex)){
				addError("msg", "请输入性别");
				return;
			}
			controller.setAttr("customer", customer);
			controller.setAttr("mAge", mAge);
		}
		else if(actionKey.equals("/customerInfo/saveCustomerDetail")){
			valiSaveCustomerDetail();
		}
		
	}
	protected  void  valiSaveCustomerDetail()
	{
		CustomerDetail  customerDetail = controller.getModel(CustomerDetail.class);
		String   height=customerDetail.getInt(CustomerDetail.column_height).toString();
		String   weight=customerDetail.getFloat(CustomerDetail.column_firstWeight).toString();
		if(StringUtil.isBlank(height)){
			addError("msg", "请输入身高");
			return;
		}
		if(StringUtil.isBlank(weight)){
			addError("msg", "请输入体重");
			return;
		}
		controller.setAttr("customerDetail", customerDetail);
	}
	
	
	@Override
	protected void handleError(Controller paramController) {
		// TODO Auto-generated method stub
		controller.render(AjaxRender.error((String)controller.getAttr("msg")));
	}

}
